<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<form *ngIf="datesForm" [formGroup]="datesForm">
  <div class="more-filters__body__block">
    <span class="more-filters__body__title">Date</span>
    <mat-form-field>
      <mat-label>Period</mat-label>
      <mat-select formControlName="period" aria-label="Period selection">
        <mat-option *ngFor="let period of periods" [value]="period">{{ period.label }}</mat-option>
      </mat-select>
    </mat-form-field>

    <mat-form-field>
      <mat-label>From</mat-label>
      <input matInput [owlDateTime]="fromDateTimePicker" formControlName="from" />
      <mat-icon [owlDateTimeTrigger]="fromDateTimePicker" matSuffix svgIcon="gio:nav-arrow-down"></mat-icon>
      <owl-date-time #fromDateTimePicker></owl-date-time>
    </mat-form-field>

    <mat-form-field>
      <mat-label>To</mat-label>
      <input matInput [owlDateTime]="toDateTimePicker" [min]="minDate" formControlName="to" />
      <mat-icon [owlDateTimeTrigger]="toDateTimePicker" matSuffix svgIcon="gio:nav-arrow-down"></mat-icon>
      <owl-date-time #toDateTimePicker></owl-date-time>
      <mat-error *ngIf="datesForm.get('to').hasError('owlDateTimeMin')">
        <span> Date time value must be after {{ datesForm.get('from').value | date: 'yyyy-MM-dd HH:mm:ss' }} </span>
      </mat-error>
    </mat-form-field>
  </div>
</form>

<form *ngIf="moreFiltersForm" [formGroup]="moreFiltersForm">
  <div class="more-filters__body__block">
    <span class="more-filters__body__title">Response</span>
    <mat-form-field>
      <mat-label>Status</mat-label>
      <mat-chip-grid #statusChipList aria-label="Status chips" formControlName="statuses">
        <mat-chip-row removable="true" selectable="false" *ngFor="let status of statuses" [value]="status" (removed)="removeStatus(status)">
          {{ status }}
          <button matChipRemove>
            <mat-icon>cancel</mat-icon>
          </button>
        </mat-chip-row>
        <input
          type="number"
          placeholder="HTTP status"
          [matChipInputAddOnBlur]="true"
          [matChipInputFor]="statusChipList"
          (matChipInputTokenEnd)="addStatusFromInput($event)"
        />
      </mat-chip-grid>
    </mat-form-field>
  </div>
  <div class="more-filters__body__block">
    <span class="more-filters__body__title">Activity</span>
    <applications-filter formControlName="applications" (applicationCache)="this.applicationsCache = $event"></applications-filter>
  </div>
</form>
